package org.mech.sefer.client.app.spring;

import org.mech.sefer.client.app.Lifecycle;
import org.mech.sefer.client.app.SeferClient;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * <p>
 * The SpringLoader is {@link Lifecycle} implementation that starts spring
 * context on start and close on shutdown of client
 * </p>
 * <p>
 * Date: 2.5.2012 17:07:53
 * </p>
 * 
 * @author martin.krajc
 */
public class SpringLoader implements Lifecycle {

	private AbstractApplicationContext applicationContext;

	@Override
	public void onStart(SeferClient client) {
		applicationContext = new ClassPathXmlApplicationContext(
				"/org/mech/sefer/client/context/client-root.xml");
		applicationContext.start();
		client.setApplicationContext(applicationContext);

	}

	@Override
	public void onShutdown(SeferClient client) {
		applicationContext.close();
	}

}
